from DrissionPage import ChromiumPage

class EyouAutoMation:
    def __init__(self,page:ChromiumPage)-> None:
        self.page = page
        
    def start(self,url,username,password):       
        # 跳转到登录页面
        self.page.get(url)
        # 定位到账号文本框，获取文本框元素，输入对文本框输入账号
        self.page.ele('@name=user_name').input(username)
        # 定位到密码文本框并输入密码
        self.page.ele('@name=password').input(password)
        # 验证码
        yzm = input('enter code:')
        self.page.ele('@name=vertify').input(yzm)
        # 点击登录按钮
        self.page.ele('@name=submit').click()

    def article_manage(self):
        self.page.ele('#Archives_index').click()
        # self.page.ele('#tree_4_span').click()
        # 救援常识
        self.page.ele('#tree_16_span').click()
        self.page.wait(0.5)

    def article_copy(self,webseo):
        # 选择要复制的文章并复制
        self.page.ele('tag:input@@name=ids[]').click()
        self.page.ele('批量操作').click()
        self.page.ele('复制文档').click()
        self.page.wait(1)
        self.page.ele('#post_form').ele('@name=num').clear()
        self.page.ele('#post_form').ele('@name=num').input('1')
        self.page.ele('#post_form').ele('tag:input@@value=确认提交').click()
        self.page.wait(2.5)
        # 编辑复制的文章
        self.page.ele('#flexigrid').ele('tag:table').ele('tag:tbody').ele('tag:tr').ele('tag:td@@class=operation').ele('编辑').click()
        # 清空需要填充的输入框
        self.page.wait(2)
        # 标题
        self.page.ele('#title').clear()
        self.page.ele('#title').input(webseo['title'])
        # 封面
        self.page.ele('#litpic_local').clear()
        self.page.ele('#litpic_local').input(webseo['litpic'])
        # TAG
        self.page.ele('SEO选项').click()
        self.page.ele('#tags').input(webseo['keywords'])
        # seo标题
        self.page.ele("#seo_title").clear()
        self.page.ele("#seo_title").input(webseo['title'])
        # seo关键字
        self.page.ele("#seo_keywords").clear()
        self.page.ele("#seo_keywords").input(webseo['keywords'])
        # 保存
        self.page.ele('#submitBtn').click()
        # #返回列表
        self.page.ele('tag:a@@text()=已发布文档管理').click()
        self.page.wait(0.5)
